package com.hxd.tabactivityfragment.mvp.presenter

import com.hxd.tabactivityfragment.bean.UserBean
import com.hxd.tabactivityfragment.mvp.base.IBasePresenter
import com.hxd.tabactivityfragment.mvp.model.RegisterModel
import com.hxd.tabactivityfragment.mvp.view.IRegisterView

/**
 *  项目名：    FoodOrigins
 *  包名：      com.hxd.tabactivityfragment.mvp.presenter
 *  文件名:     RegisterPresenter
 *  创建者:     HXD
 *  创建时间:   2019/3/31 16:46
 *  描述:       TODO
 */

class RegisterPresenter:IBasePresenter {

    private val mRegisterModel by lazy { RegisterModel() }
    private var mRegisterView: IRegisterView? = null

    /**
     * 注册业务
     */
    fun register(){
        val name = mRegisterView!!.getName()
        val account = mRegisterView!!.getAccount()
        val password = mRegisterView!!.getPassword()
        val confirmPassword = mRegisterView!!.getconfirmPassword()
        mRegisterModel.register(name, account, password, confirmPassword, object :RegisterModel.OnRegisterResultListener{
            override fun registerSuccess(user: UserBean) {
                mRegisterView!!.registerSuccess(user)
            }

            override fun registerFailure(msg: String) {
                mRegisterView!!.getDataFail(msg)
            }
        })
    }



    override fun destoryView() {
        if (mRegisterView != null){
            mRegisterView = null
        }
    }

    override fun bindView(view: Any) {
        mRegisterView = view as IRegisterView
    }
}